package org.come.Jpanel;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.PetPanelBtn;
import com.tool.tcpimg.UIUtils;
import org.come.Frame.ZhuFrame;
import org.come.entity.Goodstable;
import org.come.until.CutButtonImage;
import org.come.until.GoodsListFromServerUntil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;

/**
 * 葫芦降世主面板
 */
public class SyntheticGourdDollJpanel extends JPanel {

    private PetPanelBtn btnHuaLian;
    private JLabel[] goodsLabels;
    private Integer[] goodsIndexs;

    public SyntheticGourdDollJpanel() {
        this.setLayout(null);
        this.setPreferredSize(new Dimension(659, 461));
        this.setBackground(new Color(0, 0, 0, 0));
        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 702);
        offBtn.setBounds(659 - 33, 10, 25, 25);
        this.add(offBtn);

        goodsLabels = new JLabel[7];
        goodsIndexs = new Integer[7];
        int[] xArr = {168,308,449,540,386,231,89};
        int[] yArr = {146,129,146,215,280,280,220};
        int[] ids = {359,360,361,362,363,364,365};// 物品ID
        for (int i = 0; i < goodsLabels.length; i++) {
            goodsLabels[i] = new JLabel();
            goodsLabels[i].setBounds(xArr[i], yArr[i], 59, 59);
            int finalI = i;
            goodsLabels[i].addMouseListener(new MouseListener() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    Goodstable goods = GoodsListFromServerUntil.getGoodsById(BigDecimal.valueOf(ids[finalI]));
                    if (goods != null) {
                        goodsLabels[finalI].setIcon(CutButtonImage.getImage("inkImg/button/" + goods.getSkin() + ".png", -1, -1));
                        goodsIndexs[finalI] =GoodsListFromServerUntil.getGoodsIndexById(goods.getRgid());;

                        boolean isShow = true;
                        for (int j = 0; j < goodsIndexs.length; j++) {
                            if (goodsIndexs[j] == null) {
                                isShow = false;
                            }
                        }
                        btnHuaLian.setVisible(isShow);
                    } else {
                        ZhuFrame.getZhuJpanel().addPrompt2("没有物品");
                    }
                }

                @Override
                public void mousePressed(MouseEvent e) {

                }

                @Override
                public void mouseReleased(MouseEvent e) {

                }

                @Override
                public void mouseEntered(MouseEvent e) {

                }

                @Override
                public void mouseExited(MouseEvent e) {

                }
            });
            this.add(goodsLabels[i]);
        }
        btnHuaLian = new PetPanelBtn("inkImg/button/81.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.HYXLSJ17, "召唤", 16, this);
        btnHuaLian.setBounds(180, 365, 113,34);
        this.add(this.btnHuaLian);
    }
    public void clear() {
        btnHuaLian.setVisible(false);
        for (int i = 0; i < goodsLabels.length; i++) {
            goodsIndexs[i] = null;
            goodsLabels[i].setIcon(null);
        }
    }

    private ImageIcon icon;
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (this.icon == null) {
            this.icon = new ImageIcon("inkImg/background/S321.png");
        }

        btnHuaLian.setBounds(283, 378, 113,34);
        g.drawImage(this.icon.getImage(), 0, 0, 659, 461, this);
    }

    public Integer[] getGoodsIndexs() {
        return goodsIndexs;
    }

    public void setGoodsIndexs(Integer[] goodsIndexs) {
        this.goodsIndexs = goodsIndexs;
    }
}
